package com.andnux.android.adapter;

import android.view.View;

import com.andnux.android.data.Works;
import com.andnux.android.databinding.ItemWorksBinding;
import com.andnux.android.network.GsonUtils;
import com.andnux.android.utils.ImageLoader;
import com.google.gson.reflect.TypeToken;

import java.util.List;

public class WorksAdapter extends BaseAdapter<Works, ItemWorksBinding> {

    @Override
    public void onBindView(ItemWorksBinding itemWorksBinding, Works works, int position) {
        super.onBindView(itemWorksBinding, works, position);
        String json = works.getFiles();
        List<String> files = GsonUtils.gson.fromJson(json, new TypeToken<List<String>>() {
        }.getType());
        ImageLoader.load(files.get(0), itemWorksBinding.imageView);
        itemWorksBinding.title.setText(works.getTitle());
        itemWorksBinding.username.setText(works.getUsers().getNickname());
        ImageLoader.load(works.getUsers().getAvatar(), itemWorksBinding.header);
        itemWorksBinding.shz.setVisibility(works.getStatus() == 0 ? View.VISIBLE:View.GONE);
    }
}
